package com.lm.itextpdf.example;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;

public class MergePDFExample {
    public static void main(String[] args) throws Exception {
        String[] srcFiles = {"file1.pdf", "file2.pdf"};
        String dest = "merged.pdf";

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

        for (String src : srcFiles) {
            PdfDocument srcDoc = new PdfDocument(new PdfReader(src));
            srcDoc.copyPagesTo(1, srcDoc.getNumberOfPages(), pdfDoc);
            srcDoc.close();
        }

        pdfDoc.close();
        System.out.println("PDF merged at: " + dest);
    }
}
